﻿Imports drawing.CommonInterfaces.UI.interfaces

Public Class BozoDetector
    Implements Idetector
    Dim _location As Point
    Public sight(3) As Rectangle
    Dim _detected As ICollection(Of IShape)
    Dim sightRange As Integer = 200


    Public Sub New()
        location = New Point(0, 0)
        _detected = New List(Of IShape)
        setSightRange(sightRange)

    End Sub

    Public Sub New(ByVal location As Point)
        _location = location
        _detected = New List(Of IShape)
        setSightRange(sightRange)
    End Sub

    Public Sub setSightRange(ByVal diameter As Integer)
        Dim upperleft1 As Point
        Dim upperleft2 As Point
        Dim upperleft3 As Point
        upperleft1 = New Point(location.X - diameter / 2, location.Y - diameter / 4)
        upperleft2 = New Point(location.X - diameter / 4, location.Y - diameter / 2)
        upperleft3 = New Point(location.X - diameter / 2, location.Y - diameter / 2)
        sight(0) = New Rectangle(upperleft1, New Size(diameter, diameter / 2))
        sight(1) = New Rectangle(upperleft2, New Size(diameter / 2, diameter))
        sight(2) = New Rectangle(upperleft3, New Size(diameter, diameter))

    End Sub

    Public Sub detect(ByVal TheWorld As world.environement.World) Implements CommonInterfaces.UI.interfaces.Idetector.detect
        _detected = New List(Of IShape)
        For Each thing As IShape In TheWorld.population
            If TypeOf thing Is bozo.bozo Then
                Dim isIn As Boolean = False
                For Each rect As Rectangle In sight
                    If rect.IntersectsWith(thing.getClippingRcangle()) Then
                        isIn = True
                    End If
                Next
                If isIn Then
                    _detected.Add(thing)
                End If
            End If
        Next
    End Sub

    Public Property detected() As System.Collections.Generic.ICollection(Of CommonInterfaces.UI.interfaces.IShape) Implements CommonInterfaces.UI.interfaces.Idetector.detected
        Get
            Return _detected
        End Get
        Set(ByVal value As System.Collections.Generic.ICollection(Of CommonInterfaces.UI.interfaces.IShape))
            _detected = value
        End Set
    End Property

    Public Property location() As System.Drawing.Point Implements CommonInterfaces.UI.interfaces.Idetector.location
        Get
            Return _location
        End Get
        Set(ByVal value As System.Drawing.Point)
            _location = value
            setSightRange(sightRange)
        End Set
    End Property
End Class
